<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="区域" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="districtId">
  	          <j-tree-select
                ref="treeSelect"
                placeholder="请选择区域"
                v-model="model.districtId"
                dict="rfb_district,name,id"
                pidValue="0"
                >
              </j-tree-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="社区" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="communityId">
              <j-dict-select-tag type="list" v-model="model.communityId" dictCode="rfb_base_community,name,id" placeholder="请选择社区" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="网格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gridId">
              <j-dict-select-tag type="list" v-model="model.gridId" dictCode="rfb_grid_main,grid_name,id" placeholder="请选择网格" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="category">
              <j-dict-select-tag type="list" v-model="model.category" dictCode="affair_type_code" placeholder="请选择事件类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件概述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="summarize">
              <a-input v-model="model.summarize" placeholder="请输入事件概述"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图片地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="image">
              <a-input v-model="model.image" placeholder="请输入图片地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="视频地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="video">
              <a-input v-model="model.video" placeholder="请输入视频地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否处理" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <j-dict-select-tag type="list" v-model="model.status" dictCode="execute_code" placeholder="请选择是否处理" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="处理人员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="excutePeople">
              <j-dict-select-tag type="list" v-model="model.excutePeople" dictCode="rfb_grid_employee,employee_name,id" placeholder="请选择处理人员" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="上报人员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reportPeople">
              <j-dict-select-tag type="list" v-model="model.reportPeople" dictCode="rfb_base_resident,name,id" placeholder="请选择上报人员" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'RfbAffairMainForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           districtId: [
              { required: true, message: '请输入区域!'},
           ],
           communityId: [
              { required: true, message: '请输入社区!'},
           ],
           gridId: [
              { required: true, message: '请输入网格!'},
           ],
           category: [
              { required: true, message: '请输入事件类型!'},
           ],
        },
        url: {
          add: "/affairmain/rfbAffairMain/add",
          edit: "/affairmain/rfbAffairMain/edit",
          queryById: "/affairmain/rfbAffairMain/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>